/*
day301
2020.6.24
*/
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;

class Solution {
	public:
		vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {
			map<int,int> m;
			for(int i=0; i<arr2.size(); ++i) {
				m[arr2[i]]=i;
			}

			sort(arr1.begin(),arr1.end(),[&m](int a,int b)->bool {
				if(m.find(a)!=m.end() && m.find(b)!=m.end()) {
					return m[a]<m[b];
				}

				else if(m.find(a)!=m.end()) {
					return true;
				}

				else if(m.find(b)!=m.end()) {
					return false;
				}
				return (a<b);
			});

			return arr1;
		}
};


int main() {
	return 0;
}
